package views;

import views.panels.PanelGeneral;
import logicBusiness.LaboratorioBL;
import models.Laboratorio;
import java.awt.BorderLayout;
import java.util.List;
import javax.swing.table.TableColumn;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author vanessa 
 */
public class InterfazReporteLaboratorio extends javax.swing.JFrame {

    private LaboratorioBL laboratoriobo;

    /** Creates new form InterfazReporteLaboratorio */
    public InterfazReporteLaboratorio() {
        initComponents();
        PanelGeneral panel = new PanelGeneral();
        this.add(panel, BorderLayout.SOUTH);



        TableColumn column = null;

        /*Cambio el ancho de las columnas de la tabla TLaboratorio*/
        column = this.TLaboratorio.getColumnModel().getColumn(0);
        column.setPreferredWidth(85);
        column = this.TLaboratorio.getColumnModel().getColumn(1);
        column.setPreferredWidth(100);
        column = this.TLaboratorio.getColumnModel().getColumn(2);
        column.setPreferredWidth(100);
        column = this.TLaboratorio.getColumnModel().getColumn(3);
        column.setPreferredWidth(120);
        column = this.TLaboratorio.getColumnModel().getColumn(4);
        column.setPreferredWidth(120);


        laboratoriobo = new LaboratorioBL();
        this.inicializarTablaLaboratorio();

    }

    private void inicializarTablaLaboratorio() {
        List<Laboratorio> listaLaboratorio = laboratoriobo.obtenerListLaboratorio();
        int numfilas = listaLaboratorio.size();

        TLaboratorio.setModel(new DefaultTableModelImpl(
                new Object[numfilas][5],
                new String[]{
                    "Número", "Nombre", "Capacidad", "Disponible", "Descripcion"
                }));


        for (int indicefilas = 0; indicefilas < numfilas; indicefilas++) {
//            this.TLaboratorio.setValueAt(listaLaboratorio.get(indicefilas).getIdLaboratorio(), indicefilas, 0);
//            this.TLaboratorio.setValueAt(listaLaboratorio.get(indicefilas).getnombreLab(), indicefilas, 1);
//            this.TLaboratorio.setValueAt(listaLaboratorio.get(indicefilas).getcapacidadlab(), indicefilas, 2);
//            this.TLaboratorio.setValueAt(listaLaboratorio.get(indicefilas).getdisponibildaLab(), indicefilas, 3);
//            this.TLaboratorio.setValueAt(listaLaboratorio.get(indicefilas).getdescripcionLab(), indicefilas, 4);

        }
    }

    private class DefaultTableModelImpl extends DefaultTableModel {

        public DefaultTableModelImpl(Object[][] arg0, Object[] arg1) {
            super(arg0, arg1);
        }
        boolean[] canEdit = new boolean[]{false, false, false, false, false, true};

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit[columnIndex];
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        SPSelectLab = new javax.swing.JScrollPane();
        TLaboratorio = new javax.swing.JTable();
        BConsultarLab = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        SPHorarioLab = new javax.swing.JScrollPane();
        THorarioLab = new javax.swing.JTable();
        jLabel3 = new javax.swing.JLabel();
        CTCapacidadLab = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        CTDescripcionLab = new javax.swing.JTextField();
        BAceptar = new javax.swing.JButton();

        setResizable(false);

        jLabel1.setText("Seleccione el laboratorio a consultar:");

        TLaboratorio.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Numero ", "Nombre", "Capacidad", "Disponible", "Descripcion"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.Integer.class, java.lang.Boolean.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        SPSelectLab.setViewportView(TLaboratorio);

        BConsultarLab.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        BConsultarLab.setText("Consultar Información Laboratorio");
        BConsultarLab.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BConsultarLabActionPerformed(evt);
            }
        });

        jLabel2.setText("Horario del Laboratorio:");

        THorarioLab.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Hora", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes"
            }
        ));
        SPHorarioLab.setViewportView(THorarioLab);

        jLabel3.setText("Capacidad del Laboratorio:");

        CTCapacidadLab.setEditable(false);

        jLabel4.setText("Descripción del Laboratorio:");

        CTDescripcionLab.setEditable(false);

        BAceptar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        BAceptar.setText("Aceptar");
        BAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BAceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(SPHorarioLab, javax.swing.GroupLayout.DEFAULT_SIZE, 806, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(SPSelectLab, javax.swing.GroupLayout.DEFAULT_SIZE, 806, Short.MAX_VALUE)
                            .addComponent(jLabel1)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(CTCapacidadLab, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel4)
                        .addGap(14, 14, 14)
                        .addComponent(CTDescripcionLab, javax.swing.GroupLayout.DEFAULT_SIZE, 659, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(277, 277, 277)
                        .addComponent(BAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(233, Short.MAX_VALUE)
                .addComponent(BConsultarLab, javax.swing.GroupLayout.PREFERRED_SIZE, 373, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(220, 220, 220))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(SPSelectLab, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(17, 17, 17)
                .addComponent(BConsultarLab)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(SPHorarioLab, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(CTCapacidadLab, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CTDescripcionLab, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(31, 31, 31)
                .addComponent(BAceptar)
                .addGap(48, 48, 48))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BAceptarActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_BAceptarActionPerformed

    private void BConsultarLabActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BConsultarLabActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_BConsultarLabActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new InterfazReporteLaboratorio().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BAceptar;
    private javax.swing.JButton BConsultarLab;
    private javax.swing.JTextField CTCapacidadLab;
    private javax.swing.JTextField CTDescripcionLab;
    private javax.swing.JScrollPane SPHorarioLab;
    private javax.swing.JScrollPane SPSelectLab;
    private javax.swing.JTable THorarioLab;
    private javax.swing.JTable TLaboratorio;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    // End of variables declaration//GEN-END:variables
}
